import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/class/page/classroom_hasbuy_page.dart';
import 'package:flutter_douban/main_page/class/provider/class_provider_model.dart';
import 'package:provider/provider.dart';

class ClassNavView extends StatefulWidget {
  const ClassNavView({Key? key}) : super(key: key);

  @override
  _ClassNavViewState createState() => _ClassNavViewState();
}

class _ClassNavViewState extends State<ClassNavView> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 45,
      color: Colors.white,
      margin: EdgeInsets.only(left: 0, right: 0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _leftView(),
          _messageView(),
        ],
      ),
    );
  }

  Widget _leftView() {
    return SizedBox(
      width: MediaQuery.of(context).size.width - 80,
      height: 35,
      child: FlatButton(
        onPressed: () => print(''),
        child: Row(
          children: [
            Image(
              image: AssetImage("assets/images/common/button_search_gray.png"),
              fit: BoxFit.cover,
              width: 18,
              height: 18,
            ),
            SizedBox(
              width: 5,
            ),
            Text(
              '搜索感兴趣的课程',
              style: TextStyle(
                color: Colors.black26,
                fontSize: 14,
              ),
            )
          ],
        ),
        color: AppColors.page,
        shape: RoundedRectangleBorder(
            side: BorderSide(
              color: AppColors.page,
              width: 0.5,
            ),
            borderRadius: BorderRadius.circular(1)),
      ),
    );
  }

  /// 消息
  Widget _messageView() {
    return Stack(
      children: [
        InkWell(
          child: Container(
            width: 45,
            height: 40,
            alignment: Alignment.center,
            child: Text(
              '已购买',
              style: TextStyle(
                  fontSize: 14, color: Color.fromRGBO(94, 146, 140, 1)),
            ),
          ),
          onTap: () {
            Navigator.of(context).push(MaterialPageRoute(builder: (_) {
              return ClassRoomHasBuyPage();
            }));
          },
        ),
        Positioned(
          right: 0,
          top: 0,
          child: Container(
              width: 16,
              height: 16,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: AppColors.danger,
                borderRadius: BorderRadius.circular(10),
              ),
              child: Text(
                '${Provider.of<ClassProviderModel>(context).count}',
                style: TextStyle(fontSize: 9, color: Colors.white),
              )),
        ),
      ],
    );
  }
}
